import { ElLoading } from 'element-plus';

/**
 * options参数如下
 * @param {*} options https://element-plus.gitee.io/#/zh-CN/component/loading#options
 * @returns 
 */
const createLoading = (options = {})=>{
  // 是否在加载中
  let loadingStatus = false;
  // 开启loading方法返回的对象
  let service = null;

  // 执行加载方法
  const open = ()=>{
    if(!loadingStatus){
      loadingStatus = true;
      service = ElLoading.service(options);
    }
  }

  // 关闭加载效果
  const close = ()=>{
    loadingStatus = false
    service && service.close();
    service = null;
  }

  return {
    open, close
  }
}

const loading = createLoading();

export default loading